﻿@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
}
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title>仓库管理新增</title>
	<!-- 请勿在项目正式环境中引用该 layui.css 地址 -->
	<link href="//unpkg.com/layui@2.10.1/dist/css/layui.css" rel="stylesheet">
</head>
<body>

	<form class="layui-form" action="" id="baseStoreForm">
		<table>
			<tr>
				<td>
					<label class="layui-input-inline" style="width:auto">仓库代码</label>
					<div class="layui-input-inline">
						<input style="width:auto" type="text" name="baseCode" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
					</div>
				</td>
				<td>
					<label class="layui-input-inline" style="width:auto">仓库名称</label>
					<div class="layui-input-inline">
						<input style="width:auto" type="text" name="baseName" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
					</div>
					
				</td>
			</tr>
		</table>

		<table>
			<tr>
				<td>
					<div class="layui-input-inline">
						<label class="layui-input-inline" style="width:auto">仓库料品</label>
						<div class="layui-input-inline">
							<select name="warehousematerials" lay-filter="aihao">
								<option value="" select></option>
								<option value="成品">成品</option>
								<option value="装配件">装配件</option>
								<option value="零部件">零部件</option>
								<option value="原材料">原材料</option>
								<option value="五金件">五金件</option>
								<option value="包装物">包装物</option>
								<option value="半成品">半成品</option>
								<option value="电容">电容</option>
							</select>
						</div>
					</div>
				</td>
			</tr>
			<tr>
				<td>
					<div class="layui-input-inline">
						<label class="layui-input-inline" style="width:auto">入库类型</label>
						<div class="layui-input-inline">
							<select name="storageTypes" lay-filter="aihao">
								<option value=""></option>
								<option value="采购入库">采购入库</option>
								<option value="生产入库">生产入库</option>
								<option value="委外入库">委外入库</option>
								<option value="其它入库">其它入库</option>
							</select>
						</div>
					</div>
				</td>
			</tr>
			<tr>
				<td>
					<div class="layui-input-inline">
						<label class="layui-input-inline" style="width:auto">出库类型</label>
						<div class="layui-input-inline">
							<select name="outboundtypes" lay-filter="aihao">
								<option value=""></option>
								<option value="销售出库">销售出库</option>
								<option value="生产出库" selected>生产出库</option>
								<option value="委外出库">委外出库</option>
								<option value="其他出库">其他出库</option>
							</select>
						</div>
					</div>
				</td>
			</tr>
		</table>
		<table>
			<tr>
				<td>
					<div class="layui-input-inline">
						<label class="layui-input-inline">货位</label>
						<div class="layui-input-inline">
							<!-- 修改 value 值为布尔值字符串 -->
							<input type="radio" name="freight" value="true" title="启用" checked>
							<input type="radio" name="freight" value="false" title="不启用">
						</div>
					</div>
				</td>
				<td>
					<div class="layui-input-inline">
						<label class="layui-input-inline" style="width:auto">到货类型</label>
						<div class="layui-input-inline">
							<select name="arrivaltype" lay-filter="aihao">
								<option value=""></option>
								<option value="零部件">零部件</option>
								<option value="原材料">原材料</option>
								<option value="五金">五金</option>
							</select>
						</div>
					</div>
				</td>
			</tr>
			<tr>
				<td>
					<div class="layui-input-inline">
						<label class="layui-input-inline">仓库期间</label>
						<div class="layui-input-inline">
							<input type="radio" name="during" value="true" title="自然月" checked>
							<input type="radio" name="during" value="false" title="固定日">
						</div>
					</div>
				</td>
				<td>
					<div class="layui-inline">
						<label class="layui-input-inline" style="width:auto">验证日期</label>
						<div class="layui-input-inline layui-input-wrap">
							<div class="layui-input-prefix">
								<i class="layui-icon layui-icon-date"></i>
							</div>
							<input style="width:auto" type="text" name="beginDisposition" id="date" lay-verify="date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
						</div>
					</div>
				</td>
			</tr>
			<tr>
				<td>
					<div class="layui-input-inline">
						<label class="layui-input-inline">仓库状态</label>
						<div class="layui-input-inline">
							<input type="radio" name="baseState" value="true" title="启用" checked>
							<input type="radio" name="baseState" value="false" title="停用">
						</div>
					</div>
				</td>
				<td>
					<label class="layui-input-inline" style="width:auto">表单配置</label>
					<div class="layui-input-inline">
						<input style="width:auto" type="text" name="fromDisposition" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
					</div>
				</td>
			</tr>
			<tr>
				<td>
					<div class="layui-input-inline">
						<label class="layui-input-inline" style="width:auto">仓管员</label>
						<div class="layui-input-inline">
							<select name="baseKeeper" lay-filter="aihao">
								<option value=""></option>
								<option value="周莹">周莹</option>
								<option value="周桂东">周桂东</option>
								<option value="石伪善">石伪善</option>
								<option value="袁华">袁华</option>
								<option value="渤哥">渤哥</option>
							</select>
						</div>
					</div>
				</td>
				<td>
					<div class="layui-input-inline">
						<label class="layui-input-inline" style="width:auto">操作员</label>
						<div class="layui-input-inline">
							<select name="baseTodo" lay-filter="aihao">
								<option value=""></option>
								<option value="张三">张三</option>
								<option value="李四">李四</option>
								<option value="王五">王五</option>
								<option value="赵六">赵六</option>
								<option value="钱七">钱七</option>
							</select>
						</div>
					</div>
				</td>
			</tr>
		</table>
		<div class="layui-input-inline">
			<div class="layui-input-inline">
				<button type="submit" class="layui-btn" lay-submit lay-filter="demo1">立即提交</button>
				<button type="reset" class="layui-btn layui-btn-primary">重置</button>
			</div>
		</div>
	</form>

	<!-- 请勿在项目正式环境中引用该 layui.js 地址 -->
	<script src="//unpkg.com/layui@2.10.1/dist/layui.js"></script>
	<script>
		// 使用LayUI的模块化加载
		layui.use(['form', 'laydate', 'jquery', 'layer'], function(){
			// 获取LayUI模块的引用
			var form = layui.form;      // 表单模块
			var layer = layui.layer;    // 弹层模块
			var laydate = layui.laydate; // 日期模块
			var $ = layui.jquery;       // jQuery模块

			// 初始化日期选择器
			// 绑定到ID为"date"的输入框
			laydate.render({
				elem: '#date',          // 指定元素
				//format: 'yyyy-MM-dd'    // 日期格式（已在HTML中设置）
			});

			// 监听表单提交事件
			// 'submit(demo1)'中的demo1对应按钮的lay-filter属性
			form.on('submit(demo1)', function(data){
				var fromData=data.field
				var postData={
					baseCode:fromData.baseCode,
					baseName:fromData.baseName,
					warehousematerials:fromData.warehousematerials,
					storageTypes:fromData.storageTypes,
					outboundtypes:fromData.outboundtypes,
					freight:fromData.freight===true,
					arrivaltype:fromData.arrivaltype,
					during:fromData.during===true,
					beginDisposition:fromData.beginDisposition,
					baseState:fromData.baseState===true,
					fromDisposition:fromData.fromDisposition,
					baseKeeper:fromData.baseKeeper,
					baseTodo:fromData.baseTodo

				}
				console.log(data)
				// data.field包含表单所有字段的键值对
				//freight freight
				//freight

				// 显示加载中提示
				var index = layer.load(1, {
					shade: [0.1,'#fff'] // 0.1透明度的白色背景
				});

				// 使用Ajax提交表单数据
				$.ajax({
					//url: 'http://localhost:5090/api/BaseStoragemanage/AddBaseStore', 
					url: "@ViewBag.BaseUrl/T8/BaseStoragemanage/AddBaseStore",
					type: 'POST',                               // 请求方法
					contentType: 'application/json',            // 内容类型为JSON
					data: JSON.stringify(postData),           // 将表单数据转为JSON字符串
					dataType: 'json',                           // 预期服务器返回的数据类型

					// 请求成功回调函数
					success: function(res) {
						// 关闭加载提示
						layer.close(index);
						console.log(res)

						// 根据返回的code判断是否成功
						if(res.code == 212) {
							// 成功提示
							layer.alert(res.test, {
								title: '操作成功', // 标题
								icon: 1,           // 图标类型：1=成功
								btn: ['确定'],      // 按钮
								yes: function(index, layero){
									// 点击确定后的回调
									// 重置表单
									document.getElementById("baseStoreForm").reset();
									// 重新渲染表单（针对LayUI的特殊控件）
									form.render();
									layer.close(index); // 关闭弹窗
									//location.href=""
								}
							});
						} else {
							// 失败提示
							layer.alert(res.test, {
								title: '操作失败',
								icon: 2 // 图标类型：2=失败
							});
						}
					},

					// 请求失败回调函数
					error: function(xhr, status, error) {
						// 关闭加载提示
						layer.close(index);

						// 错误提示
						layer.alert('请求失败: ' + error, {
							title: '错误',
							icon: 2,
							btn: ['确定']
						});

						// 可选：在控制台输出错误详情
						console.error('AJAX请求失败:', status, error);
						console.error('响应内容:', xhr.responseText);
					}
				});

				// 阻止表单默认提交行为（页面跳转）
				return false;
			});

			// 其他表单初始化代码...
			// 例如：动态加载下拉框数据等
		});
	</script>

</body>
</html>